//
//  Date+Addition.swift
//  CrazyFatReducingMeal
//
//  Created by iOS-Czz on 2023/11/8.
//

import Foundation
extension Date {
    static func formatTime(inputTime: String) -> String? {
           let formatter = DateFormatter()
           formatter.dateFormat = "HH:mm"
           
           if let date = formatter.date(from: inputTime) {
               formatter.dateFormat = "hh:mm a"
               return formatter.string(from: date)
           }
           
           return nil // 如果时间格式无效
       }
    func toString(format: String = "yyyy-MM-dd HH:mm:ss") -> String {
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = format
            return dateFormatter.string(from: self)
        }
        func getTodayDate() -> String {
            let calendar = Calendar.current
            let dayOfWeek = calendar.component(.weekday, from: self)
            let dayOfWeekString = calendar.weekdaySymbols[dayOfWeek - 1]
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "dd/MM"
            let dateString = dateFormatter.string(from: self)
            let result = "\(dateString)   \(dayOfWeekString)"
            return result
        }

}
